package training.sample.app.domain;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.NotEmpty;

@Entity
@Table(name = "client")
public class Client {
 
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "CLIENT_ID")
    private Long id;
	
	@Pattern(regexp = "[a-zA-Z0-9 ]*")
	@Size(min=1, max=32)
	@Column(name = "CLIENT_NAME")
    private String name;
	
	@NotEmpty
	@Pattern(regexp = "[-a-zA-Z0-9 ]*")
    @Column(name = "CLIENT_SSN")
    private String ssn;
    
	@Column(name = "IS_ACTIVE")
	private boolean active;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "COUNTRY_ID", nullable = false)
	private Country country;
	
	@Column(name = "BALANCE")
	private double balance;
	
	@NotEmpty
	@Column(name = "NOTES")
	private String notes;
	
	@Transient
	private String singleChoice;
	@Transient
	private String[] multipleOptions;
	@Transient
	private String[] businessFields;
	
	public Client() {}
    
    public Client(Long id, String name, String ssn) {
    	this.id = id;
    	this.name = name;
    	this.ssn = ssn;
    }
	
    @OneToOne(cascade=CascadeType.ALL, mappedBy="holder")
    private BankAccount bankAccount;

	public Long getId() {
		return id;
	}

	public void setId(Long clientId) {
		this.id = clientId;
	}

	public BankAccount getBankAccount() {
		return bankAccount;
	}

	public void setBankAccount(BankAccount bankAccount) {
		this.bankAccount = bankAccount;
	}

	public String getName() {
		return name;
	}

	public void setName(String clientName) {
		this.name = clientName;
	}

	public String getSsn() {
		return ssn;
	}

	public void setSsn(String ssn) {
		this.ssn = ssn;
	}

	public double getBalance() {
		return balance;
	}

	public void setBalance(double balance) {
		this.balance = balance;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public Country getCountry() {
		return country;
	}

	public void setCountry(Country country) {
		this.country = country;
	}

	public String getSingleChoice() {
		return singleChoice;
	}

	public void setSingleChoice(String singleChoice) {
		this.singleChoice = singleChoice;
	}

	public String[] getMultipleOptions() {
		return multipleOptions;
	}

	public void setMultipleOptions(String[] multipleOptions) {
		this.multipleOptions = multipleOptions;
	}

	public String[] getBusinessFields() {
		return businessFields;
	}

	public void setBusinessFields(String[] businessFields) {
		this.businessFields = businessFields;
	}
}